<template>
  <div>
    <router-link v-show="shouAbs" tag="div" to="/" class="heaer-abs">
      <div class="iconfont back-icon">&#xe624;</div>
    </router-link>
    <div
      class="heaer-fixed"
      :style="opacityStyle"
      v-show="!shouAbs">
      <router-link tag="div" to="/" class="header-left" >
        <div class="iconfont back-icon">&#xe624;</div>
      </router-link>
      景点详情
    </div>
  </div>
</template>

<script>
export default {
  name: 'detailHeader',
  data () {
    return {
      shouAbs: true,
      opacityStyle: {
        opacity: 0
      }
    }
  },
  methods: {
    handleScroll () {
      const top = document.documentElement.scrollTop
      if (top > 60) {
        let opacity = top / 140
        opacity = opacity > 1 ? 1 : opacity
        this.opacityStyle = { opacity }
        this.shouAbs = false
      } else {
        this.shouAbs = true
      }
    }
  },
  // 页面绑定window事件
  activated () {
    window.addEventListener('scroll', this.handleScroll)
  },
  // 页面解绑window事件
  devctivated () {
    window.removeEventListener('scroll', this.handleScroll)
  }
}
</script>
<style lang="stylus" scoped>
@import '~@/assets/styles/varibles.styl'
  .heaer-abs
    position: absolute
    top: .15rem
    left: .15rem
    width: .72rem
    line-height: .72rem
    border-radius: .4rem
    background: rgba(0, 0, 0, .5)
    text-align: center
    .back-icon
      color: #fff
      font-size: .28rem
  .heaer-fixed
    z-index: 2
    position: fixed
    top: 0
    left: 0
    right: 0
    font-size: .28rem
    background: $bgColor
    line-height: $HeaderHeight
    text-align: center
    color: #fff
    font-size: .32rem
    .header-left
      position: absolute
      top: 0
      left: 0
      width: .64rem
      .back-icon
        font-size: .4rem
</style>
